In [10]:
import numpy as np
import matplotlib.pyplot as plt

%matplotlib inline
plt.rc('figure', figsize=(12,9))

Création d'une grille 2d

In [35]:
a, b = 6, 6
x, y = np.linspace(0, a, 500), np.linspace(0, b, 500)
X, Y = np.meshgrid(x, y)

Création du champs de vecteur en fonction de la grille

In [36]:
U = 2*X-X*Y
V = 2*X*Y-3*Y

Affichage

In [37]:
plt.streamplot(X, Y, U, V)
Out[37]:
<matplotlib.streamplot.StreamplotSet at 0x7f2e4885e320>

Ajout d'un code couleur utilisant ici la norme

In [38]:
strm = plt.streamplot(X, Y, U, V, color=np.sqrt(U**2+V**2),linewidth= 2, cmap=plt.cm.viridis)
plt.colorbar(strm.lines)
Out[38]:
<matplotlib.colorbar.Colorbar at 0x7f2e48743160>